//
//  TransitionBootcamp.swift
//  FCSwiftUI
//
//  Created by 冯宣超 on 2023/2/22.
//

import SwiftUI

struct TransitionBootcamp: View {
    
    @State var showView:Bool = false
    
    var body: some View {
        ZStack(alignment: .bottom) {
            VStack {
                Button("Button") {
                    showView.toggle()
                }
                
                Spacer()
            }
            
            if showView {
                RoundedRectangle(cornerRadius: 30)
                    // UIScreen.main 这里有点问题【"Use a UIScreen instance found through context instead: i.e, view.window.windowScene.screen")】
                    .frame(height: UIScreen.main.bounds.height*0.5)
//                    .opacity(showView ? 1.0 : 0.0)
//                    .transition(.slide)
//                    .transition(.move(edge: .bottom))
                    // 这种方式的转场动画才有效果
//                    .transition(AnyTransition.scale.animation(.easeInOut))
                    // 非对称转场动画效果
//                    .transition(
//                        .asymmetric(
//                            insertion: AnyTransition.move(edge: .leading),
//                            removal: AnyTransition.move(edge: .bottom)
//                        )
//                    )
                    .transition(.asymmetric(insertion: AnyTransition.move(edge: .bottom), removal: AnyTransition.opacity.animation(.easeInOut)))
                    .animation(Animation.easeInOut)
//                    .animation(Animation.spring())
//                    .animation(Animation.default, value: showView)

            }
        }
        .edgesIgnoringSafeArea(.bottom)
    }
}

struct TransitionBootcamp_Previews: PreviewProvider {
    static var previews: some View {
        TransitionBootcamp()
    }
}
